define(function(require, exports, module) {

	"use strict";
	require("mui");
	require("jquery");
	var abpdata = require("abpinit");
	var abp = abpdata.abpstart;
	var template = require("template");
	require('http://g.alicdn.com/ilw/ding/0.8.9/scripts/dingtalk.js');
	//钉钉返回清除缓存
	var dingTalkNav = require('dd_config');
	var newAdd = require("../chioceProduct/newAdd.js");
	//选择负责人
	newAdd.newClient("", ".chioceStaff");
	//分页
	var pageIndex = 1; //当前分页
	var dataState = true; //判断如何渲染页面，true替换加载，false加载在末尾
	var pageState = 10; //判断有多少页，调用接口再动态改
	mui.init({
		swipeBack: true, //启用右滑关闭功能
		pullRefresh: { //配置分页下拉刷新
			container: '#pullrefresh',
			down: {
				callback: pulldownRefresh
			},
			up: {
				contentrefresh: '正在加载...',
				callback: pullupRefresh
			}
		}
	});
	//钉钉返回清除缓存
	//ios
	dingTalkNav.LeftNavBar();
	//ad
	dingTalkNav.leftAndroid();
	//页面初始化
	searchClientUser("", "initContentTips");

	//条件筛选
	var departmentID = "";
	var contentTips = 0;
	mui("body").on("tap", ".pop-tab-con1 li", function() {
		departmentID = $(this).attr('data-id');
		dataState = true;
		//		    searchClientUser(1111111,"searchContentTips");        //测试无数据
		searchClientUser(departmentID, "searchContentTips");
	});

	//		下滑刷新具体业务实现
	function pulldownRefresh() {
		//		startDate='';
		//		endDate='';
		//		strStatusId[0]='';
		pageIndex = 1;
		dataState = true;
		pageState = 10;
		setTimeout(function() {
			searchClientUser(departmentID, "searchContentTips");
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //刷新完成
			//			mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);    //隐藏已经没数据了
			mui('#pullrefresh').pullRefresh().refresh(true); //重新启用页面上滑加载
		}, 1500);
	}
	//		上滑加载具体业务实现
	function pullupRefresh() {
		pageIndex++;
		dataState = false;
		setTimeout(function() {
			mui('#pullrefresh').pullRefresh().endPullupToRefresh((pageState < pageIndex)); //参数为true代表没有更多数据了。
			searchClientUser(departmentID, "searchContentTips");
		}, 1500);
	}

	//departmentID获取部门信息，contentTips判断页面初始化或条件刷选
	function searchClientUser(departmentID, contentTips) {
		//dataModel需要传的模型值,option非必要参数，默认传空对象，done异步完成，fail异步失败，data.success数值成功返回
		var option = {};
		var dataModel = {
			"keyword": "", //关键字
			"orderBy": "", //排序 
			"deptId": departmentID, //部门
			"pageIndex": 1, //当前页
			"pageSize": 20 //分页数；最大分页支持100
		};
		getClientUser("outSupplierList", "#mui-list");

		function getClientUser(templateId, mainId) {
			abp.services.app.sysClientUser.getPage(dataModel, option).
			done(function(data) {
				if(data.totalCount < 1) {
					$('.mui-content').addClass(contentTips);
				} else {
					$('.mui-content').removeClass(contentTips);
				}
				var html = template(templateId, data);
				$(mainId).html(html);
				if(data.success) {

				} else {

				}
			}).fail(function(data) {

			});
		}
	}

	$('body').one('tap', '.pop-tab .pop-tab-title1', function() {
		var getInfoDepList = require("./chioceInfoDep.js");
		getInfoDepList.InfoDep("chioceSupplier", "#chioceSupplierCon");
	});

});